import { IPSAppDELogic } from '../../app/dataentity/ipsapp-delogic';
import { IPSAppDEMethod } from '../../app/dataentity/ipsapp-demethod';
import { IPSAppDataEntity } from '../../app/dataentity/ipsapp-data-entity';
import { IPSNavigateContext } from '../ipsnavigate-context';
import { IPSNavigateParam } from '../ipsnavigate-param';
import { IPSLayout } from '../layout/ipslayout';
import { IPSLayoutContainer } from '../layout/ipslayout-container';
import { IPSPanelDataRegion } from './ipspanel-data-region';
import { PSSysPanelItemImpl } from './pssys-panel-item-impl';

export class PSSysPanelContainerImplBase extends PSSysPanelItemImpl implements IPSLayoutContainer, IPSPanelDataRegion {
  get dataName(): string {
    return this.M.dataName;
  }

  get dataRegionType(): 'NONE' | 'LOGINFORM' | 'SINGLEDATA' | 'MULTIDATA' | 'INHERIT' | 'USER' {
    return this.M.dataRegionType || 'INHERIT';
  }

  get dataSourceType(): 'DEACTION' | 'DEDATASET' | 'DELOGIC' | 'APPGLOBALPARAM' | 'TOPVIEWSESSIONPARAM' | 'VIEWSESSIONPARAM' {
    return this.M.dataSourceType;
  }

  protected psappdelogic: IPSAppDELogic | null = null;

  getPSAppDELogic(): IPSAppDELogic | null {
    if (this.psappdelogic != null) return this.psappdelogic;
    const value = this.M.getPSAppDELogic;
    if (value == null) {
      return null;
    }
    const ipsappdataentity = this.getPSAppDataEntity();
    if (ipsappdataentity != null) {
      this.psappdelogic = ipsappdataentity.findPSAppDELogic(value);
    }
    return this.psappdelogic;
  }

  get psAppDELogic(): IPSAppDELogic | null {
    return this.getPSAppDELogic();
  }

  getPSAppDELogicMust(): IPSAppDELogic {
    const value = this.getPSAppDELogic();
    if (value == null) {
      throw new Error('未指定应用实体处理逻辑');
    }
    return value;
  }

  protected psappdemethod: IPSAppDEMethod | null = null;

  getPSAppDEMethod(): IPSAppDEMethod | null {
    if (this.psappdemethod != null) return this.psappdemethod;
    const value = this.M.getPSAppDEMethod;
    if (value == null) {
      return null;
    }
    const ipsappdataentity = this.getPSAppDataEntity();
    if (ipsappdataentity != null) {
      this.psappdemethod = ipsappdataentity.findPSAppDEMethod(value);
    }
    return this.psappdemethod;
  }

  get psAppDEMethod(): IPSAppDEMethod | null {
    return this.getPSAppDEMethod();
  }

  getPSAppDEMethodMust(): IPSAppDEMethod {
    const value = this.getPSAppDEMethod();
    if (value == null) {
      throw new Error('未指定应用实体方法');
    }
    return value;
  }

  protected psappdataentity: IPSAppDataEntity | null = null;

  getPSAppDataEntity(): IPSAppDataEntity | null {
    if (this.psappdataentity != null) return this.psappdataentity;
    const value = this.M.getPSAppDataEntity;
    if (value == null) {
      return null;
    }
    this.psappdataentity = this.getPSModel4('app.dataentity.IPSAppDataEntity', value, 'getPSAppDataEntity') as IPSAppDataEntity;
    return this.psappdataentity;
  }

  get psAppDataEntity(): IPSAppDataEntity | null {
    return this.getPSAppDataEntity();
  }

  getPSAppDataEntityMust(): IPSAppDataEntity {
    const value = this.getPSAppDataEntity();
    if (value == null) {
      throw new Error('未指定应用实体');
    }
    return value;
  }

  protected pslayout: IPSLayout | null = null;

  getPSLayout(): IPSLayout | null {
    if (this.pslayout != null) return this.pslayout;
    const value = this.M.getPSLayout;
    if (value == null) {
      return null;
    }
    this.pslayout = this.getPSModel4('control.layout.IPSLayout', value, 'getPSLayout') as IPSLayout;
    return this.pslayout;
  }

  get psLayout(): IPSLayout | null {
    return this.getPSLayout();
  }

  getPSLayoutMust(): IPSLayout {
    const value = this.getPSLayout();
    if (value == null) {
      throw new Error('未指定布局设置');
    }
    return value;
  }

  protected psnavigatecontexts: IPSNavigateContext[] | null = null;

  getPSNavigateContexts(): IPSNavigateContext[] | null {
    if (this.psnavigatecontexts == null) {
      this.psnavigatecontexts = this.fillChildListModel(this.M.getPSNavigateContexts, 'control.IPSNavigateContext') as IPSNavigateContext[];
    }
    return this.psnavigatecontexts;
  }

  get psNavigateContexts(): IPSNavigateContext[] | null {
    return this.getPSNavigateContexts();
  }

  findPSNavigateContext(objKey: any): IPSNavigateContext | null {
    return this.getPSModel5('control.IPSNavigateContext', this.getPSNavigateContexts(), objKey) as IPSNavigateContext;
  }

  protected psnavigateparams: IPSNavigateParam[] | null = null;

  getPSNavigateParams(): IPSNavigateParam[] | null {
    if (this.psnavigateparams == null) {
      this.psnavigateparams = this.fillChildListModel(this.M.getPSNavigateParams, 'control.IPSNavigateParam') as IPSNavigateParam[];
    }
    return this.psnavigateparams;
  }

  get psNavigateParams(): IPSNavigateParam[] | null {
    return this.getPSNavigateParams();
  }

  findPSNavigateParam(objKey: any): IPSNavigateParam | null {
    return this.getPSModel5('control.IPSNavigateParam', this.getPSNavigateParams(), objKey) as IPSNavigateParam;
  }

  get reloadTimer(): number {
    return this.M.reloadTimer != null ? this.M.reloadTimer : -1;
  }

  get cls(): string {
    return 'PSSysPanelContainerImplBase';
  }

  instanceof(cls: string): boolean {
    if (cls == 'control.IPSNavigateParamContainer' || cls == 'control.layout.IPSLayoutContainer' || cls == 'control.panel.IPSPanelDataRegion') return true;
    return super.instanceof(cls);
  }
}
